{% extends "layout.html" %}
{% block content %}
    <div class="x-nav">
        <!-- <div class="layui-col-md6">
            <button class="layui-btn" onclick="x_admin_show('添加数据点','dataItem-edit.html?channel_id='+channel_id,800,400)"><i class="layui-icon"></i>添加数据点</button>
        </div> -->
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body layui-anim layui-anim-up">
        <table id="dataItemList" class="layui-table" lay-filter="dataItem">
        </table>
        <script type="text/html" id="dataItemBar">
            <div class="layui-btn-group">
            <button type="button" class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe642;</i></button>
            </div>
        </script>    
    </div>
    <!-- <script src="../static/js/socket.io.min.js"></script> -->
    <script type="text/javascript">
        // $(document).ready(function() {
        //     namespace="/chat";
        //     var socket=io(namespace);
        //     socket.on('connect', function() {
        //         console.log('connected to server');
        //         socket.emit('channel-1', {data: 'I\'m connected!'});
        //     });
        //     socket.on('response',function (msg) {
        //         console.log(msg.data);
        //     });

        // });
        $(function  () {
            layui.use(['table','form'], function(){
                var table = layui.table;
                table.render({
                    elem: '#dataItemList'
                    ,height:'full-100'
                    ,url:'../channel/defaultDataItemList'
                    ,cols:[[
                    {title:'ID',field:'data_index',align: 'center', sort: true, fixed: true}
                    ,{title:'线圈',field:'value1',align: 'center'}
                    ,{title:'离散量',field:'value2',align: 'center'}
                    ,{title:'输入寄存器',field:'value3',align: 'center'}
                    ,{title:'保存寄存器',field:'value4',align: 'center'}
                    ,{fixed: 'right', align:'center', toolbar: '#dataItemBar'}
                    ]]
                    ,page: false
                });
                //监听工具条
                table.on('tool(dataItem)', function(obj){
                    var data = obj.data;
                    switch(obj.event){
                    case 'edit':
                        x_admin_show('编辑通道','dataItem/default-dataItem-edit.html?data_index='+obj.data.data_index,800,300);
                        break;
                    default:
                    }
                });
                table.on('rowDouble(dataItem)', function(obj){
                    var data = obj.data;
                    x_admin_show('编辑通道','dataItem/default-dataItem-edit.html?data_index='+obj.data.data_index,800,300);
                });
            });
        })



    </script>
{% endblock %}
{% block script %}
{% endblock %}